package com.hckj.jianzhijia.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.hckj.jianzhijia.BaseActivity;
import com.hckj.jianzhijia.R;
import com.hckj.jianzhijia.model.PushInfo;
import com.hckj.jianzhijia.utils.DateUtils;
//受够了，不管代码的风格了
import java.util.ArrayList;

/**
 * Created by 赵奇隆 on 2016-03-14.
 */
public class PushListAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater layoutInflater;
    private ArrayList<AVObject> arrayList;

    public final static int PUSH_APPLYING = 0;
    public final static int PUSH_FAIL = 1;
    public final static int PUSH_COMPLETED = 2;

    public PushListAdapter(Context context,ArrayList<AVObject> arrayList) {

        this.context = context;
        this.arrayList = arrayList;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        PushInfo pushInfo = new PushInfo(arrayList.get(position));;
        if(convertView == null){
            convertView = layoutInflater.inflate(R.layout.item_push_info, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        viewHolder.tv_title.setText(pushInfo.getPushTitle());
        switch (pushInfo.getState()){

            case PUSH_APPLYING:
                viewHolder.tv_state.setText("正在申请中");
            break;
            case PUSH_FAIL:
                viewHolder.tv_state.setText("申请失败");
                break;
            case PUSH_COMPLETED:
                viewHolder.tv_state.setText("推送成功");
                break;



        }
        viewHolder.tv_content.setText(pushInfo.getPushContent());
        return convertView;
    }

    private class ViewHolder {


        public TextView tv_title;
        public TextView tv_state;
        public TextView tv_content;

        public ViewHolder(View view){
            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_state = (TextView) view.findViewById(R.id.tv_state);
            tv_content = (TextView) view.findViewById(R.id.tv_content);
        }
    }
}
